package org.dant.ant.extension.net.repository;

import java.util.*;
import org.dant.ant.extension.utils.StringUtils;

public class ProcessItem {
    // real process id get from os
    protected String processID;   
  
    protected Process process;
  
    protected long startTime;
    protected long timeOut;
    protected String status;

    protected ProcessGroup group;

    public void setStatus(String s) {
        this.status = s;
    }

    public String getStatus() {
        return this.status;
    }

    public long runningTime() {
        return System.currentTimeMillis() - startTime;
    }

    public void destroy() {
        if (process != null) {
            process.destroy();
        }
    }

    public void add(Process p) {
        this.process = p;
    }

    public Process getProcess() {
        return process;
    }
  
    public void setProcessID(String processid) {
        this.processID = processid;
    }

    public String getProcessID() {
        return this.processID;
    }

    public void setStartTime(long s) {
        this.startTime = s;
    }

    public long getStartTime() {
        return this.startTime;
    }

    public void setTimeOut(long t) {
        this.timeOut = t;
    }

    public long getTimeOut() {
        return this.timeOut;
    }

    public void setOwningGroup(ProcessGroup g) {
        this.group = g;
    }

    public ProcessGroup getOwningGroup() {
        return this.group;
    }

    public String export() {
        StringBuffer sb = new StringBuffer();
        sb.append(StringUtils.formatln("***** Process Item *****", 6));
        sb.append(StringUtils.format("Process ID: ", 8));
        sb.append(StringUtils.formatln(processID + ""));
        sb.append(StringUtils.format("Start time: ", 8));
        sb.append(StringUtils.formatln(new Date(startTime).toString()));
        sb.append(StringUtils.format("Timeout: ", 8));
        sb.append(StringUtils.formatln(timeOut + ""));
        sb.append(StringUtils.format("Status: ", 8));
        sb.append(StringUtils.formatln(status));

        return sb.toString();
    }
}
